package org.agle4j.algorithm.array.unordered;

public class OperateWithValue {
	int[] datas;
	int currentIndex = 0;

	public OperateWithValue(int index) {
		this.datas = new int[index];
	}

	public int insert(int data) {
		this.datas[this.currentIndex] = data;
		this.currentIndex += 1;
		return this.currentIndex - 1;
	}

	public void remove(int data) {
		int index = getIndex(data);
		for (int i = index; i < this.currentIndex; i++) {
			this.datas[i] = this.datas[(i + 1)];
		}
		currentIndex -- ;
	}

	public int getIndex(int data) {
		for (int i = 0; i < this.currentIndex; i++) {
			if (this.datas[i] == data) {
				return i;
			}
		}
		return -1;
	}

	public int searchOne(int data) {
		return getIndex(data);
	}

	public void printDatas() {
		for (int i = 0; i < this.currentIndex; i++) {
			System.out.println(this.datas[i]);
		}
		System.out.println("////////////////////");
	}
}
